﻿/*
 * This software is the confidential and proprietary
 * information of NetBay
 * Such confidential information should not be disclosed
 * NetBay copyright(c) 2010
 */

#region Using
using System;
using System.Collections.Generic;
using System.Data.Common;
using NetBay.Core.BusinessEntities;
using Rio.Framework.Historical;
using System.Data;
#endregion

namespace Rio.Doc.Business.Repository.Translator
{
    /// <summary>
    /// Class used to convert Item database row to Item object
    /// </summary>
    public class ItemTranslator
    {
        /// <summary>
        /// Translate a bunch of Index DataReader to Index object
        /// </summary>
        /// <param name="P_oDbDataReader">The dataReader that contains the rows</param>
        /// <returns>A list of Index Object</returns>
        public static List<Item> TranslateIndex(IDataReader P_oDbDataReader)
        {
            var l_lstItems = new List<Item>();
            try
            {
                using (P_oDbDataReader)
                {
                    while (P_oDbDataReader.Read())
                    {
                        var l_oItem = new Item();
                        l_oItem.Identifier = FieldRow.Translate<long>(P_oDbDataReader["item_id"].ToString());
                        l_oItem.Name = FieldRow.Translate<string>(P_oDbDataReader["item_libelle"].ToString());
                        l_oItem.Code = FieldRow.Translate<string>(P_oDbDataReader["item_code"].ToString());
                        // Add to list
                        l_lstItems.Add(l_oItem);
                    }
                }
            }
            catch (Exception ex)
            {
                NetBay.Core.Log.LogManager.Instance().LogError(NetBay.Core.Diagnostics.Method.GetMethodBaseName(NetBay.Core.Diagnostics.Method.Level.Father) + " EXCEPTION -> " + Environment.NewLine + ex);
            }

            return l_lstItems;
        }
    }
}
